function setCheckAll(n , v)
{
	$('input[type=checkbox]').each(function()
	{
		if (this.getAttribute('name')==n)
		{
			this.checked = v;
		}
	});
}

function isCheckAll(id, n)
{
	var i_c = 1;
	$('input[type=checkbox]').each(function()
	{
		if (this.getAttribute('name')==n && !this.checked)
		{
			i_c = 0;
		}
	});
	$('input#'+id).attr('checked', i_c);
}

function getListCheckedValue(n)
{
	var result = '';
	$('input[type=checkbox]').each(function()
	{
		if (this.getAttribute('name')==n && this.checked)
		{
			result += result ? (','+this.value) : (this.value);
		}
	});
	return result;
}

function displayError(id, v, hide)
{
	if(!hide)
	{
		hideBlockUI();
	}
	$('span.err_msg').hide();
	var spanId = (v==1) ? ('err_'+id) : ('exists_'+id);
	$('span#'+spanId).show();
	$('#'+id).select();
	$('#'+id).focus();
}


/* Block UI */
function showConfirm(msg, act, act_value, id, c_name)
{
	$.getJSON
	(
		HOST_ADMIN + '/lightbox/show-confirm/?callback=?',
		{
			'msg'	: msg ,
			'a'		: act ,
			'a_v'	: act_value ,
			'i'		: id ,
			'c_name': c_name 
		},
		function(data)
		{
			showUIMessage(data.html);
		}
	);
}

function showWaiting()
{
	//return;
	var html = '<div><strong style="font-style:italic;">Processing...</strong><br/><img src="img/ajax-loader.gif"/></div>';
	showUIMessage(html);
}

function showUIMessage(msg, t) 
{
	if (msg!='') 
	{	
		$('embed').hide();
		$.blockUI
		({
			message: msg, 
			css: 
			{
				background:'#ffffff', 
				color:'#ff0000', 
				border:'4px solid #009900', 
				showOverlay: true, 
				width:'400px', 
				top: ($(window).height()-200)/2 + 'px', 
				left:($(window).width()-300)/2 + 'px', 
				padding:'5px',
				borderRadius:'8px'
			}
		});
		if (t)
		{
			setTimeout('hideBlockUI()', t*1000);
		}
	}
}

function hideBlockUI()
{
	$.unblockUI();
	$('embed').show();
}
/* Block UI */

/* Action on Form */
var v_cookieShowConfirm = 'v_cookieShowConfirm';
function doActionOnForm(act, act_value, id, cName)
{
	showWaiting();
	$.post
	(
		HOST_ADMIN + '/' + cName + '/do-act/' ,
		{
			'act'		: act ,
			'act_value'	: act_value ,
			'id'		: id 
		},
		function(data)
		{
			if (data.result=='2')
			{
				showUIMessage(gLang.global['no_per'], 3);
			}
			else if(data.result=='1')
			{
				window.location.href = window.location.href;
			}
			else
			{
				hideBlockUI();
			}
		},
		'json'
	);
}
/* Action on Form */

function countString(iE, iS, max)
{
	var e	= $('#'+iE);
	if(e)
	{
		var n 	= max - e.val().length ;
		n		= n>0 ? n : 0;
		$('#'+iS).html(n);
	}
}

/* CKEditor */
$(document).ready(function()
{
	$('a#Link_94').hide();
});
/* CKEditor */

function setLimit(v)
{
	var e	= document.frmSearch;
	if(e)
	{
		e.li.value		= v;
		e.page.value 	= 1;
		e.submit();
	}
}

function show_error(id, v)
{
	var i 	= v+ '_' + id;
	$('#'+i).removeClass('hide');
	$.unblockUI();
}
function hide_all_error()
{
	$('.error').addClass('hide');
}

function SkuCommon()
{
	this.pop_up	= function(sku, category)
	{
		showWaiting();
		$.getJSON
		(
			HOST_ADMIN + '/sku/popup/?callback=?',
			{
				'sku'	: sku,
				'c'		: category
			},
			function(data)
			{
				$('embed').hide();
				var v_width	= 1000;
				$.blockUI
				({
					message: data.html, 
					css: 
					{
						background:'#ffffff', 
						color:'#ff0000', 
						border:'4px solid #009900', 
						showOverlay: true, 
						width:v_width+'px', 
						top: '50px', 
						left:($(window).width()-v_width)/2 + 'px', 
						padding:'5px',
						borderRadius:'8px',
						cursor:'arrow'
					}
				});
			}
		);
	}
}
var SkuCommon = new SkuCommon();

/////////////////////////////MENU start /////////////////////////
function initaccord(){
	var jarrcord = jQuery('.left-menu-inner');
	if(jarrcord.length){
		var jtrigs = jarrcord.find('dt'),
			jcontents = jarrcord.find('dd'),
			animend = true;
			
		jtrigs.each(function(idx){
			jQuery(this).click(function(){
				if(!animend){
					return false;
				}
				
				animend = false;
				if(jtrigs.eq(idx).hasClass('open')){
					jtrigs.eq(idx).removeClass('open');
					jcontents.eq(idx).slideUp(function(){
						animend = true;
					});
				}
				else{
					jtrigs.eq(idx).addClass('open');
					jcontents.eq(idx).slideDown(function(){
						animend = true;
					});
				}
				
				return false;
			});
			
			if(jtrigs.eq(idx).hasClass('open')){
				jcontents.eq(idx).show();
			}
		});
	}
}
////////////////

function initMenu(){
    $("#left-menu").click(function () {
        if ($('#left-menu').length > 0) {
            $(this).toggleClass('left-menu-show');
        }
    });  	  
}
//////////////////
$(document).ready(function () {
    initaccord();
    initMenu();
    initDashboard();
});

/////////////////////MENU END //////////////////////////////

////////////////////DASH BOARD ////////////////////////////

function initDashboard() {
    $("#btnDashboard").click(function () {
        showWaiting();
        $.ajax({
            type: "GET",
            url: HOST_ADMIN + "/index/dash-board",
            success: function (data) {
                $("#div_Dashboard").html(data);
                hideBlockUI();
            }
        });
    });
}